#!/usr/bin/env python
#coding=utf-8
'''
Created on 2014-7-9

@author: Administrator
'''
from bs4 import BeautifulSoup
import requests, time
from selenium import webdriver

def get_data_from_js_page():
    Parameter = {'idNum': '051466000'}
    # 参数
    r = requests.post("http://wap.gd.10086.cn/xxt/stscore.do?action=query_record", data=Parameter)
    # 带上参数发post请求
    html_code = r.content
    # 拿到页面的内容
    soup = BeautifulSoup(html_code)
    v = soup.find_all('div', class_='viweitem')
    # print len(v)  # 总共有13个元素, 前3个和最后1个是我们是不需要的,
    '''
    print v[0]
    print v[1]
    print v[2]
    print v[len(v)-1]
    '''
    # 这4个我们是不需要的, 你可以把注释取消掉, 然后输出看看是什么.
    we_need = []
    for index in range(3, len(v)-1):
        we_need.append(v[index])
    # 从3循环到11, 跳过我们不需要的元素, 把我们需要的元素推入到一个列表里
    for one_viweitem in we_need:
        print one_viweitem.get_text()
        
def scrapy_by_soup():
    url = r'http://pan.baidu.com/disk/home#dir/path=%252F'
    req = requests.get(url)
    soup = BeautifulSoup(req.content)
    v = soup.find_all('div', class_='name-text enabled')
    print type(v)
    print v
    
def scrapy_by_webdriver():
    browser = webdriver.Firefox()
#    browser = webdriver.Ie()
    browser.get(r"http://pan.baidu.com/disk/home#dir/path=%252F")
    time.sleep(2)
    res = browser.find_element_by_class_name('item global-clearfix')
    print type(res)
    print res
    
if __name__ == "__main__":
    scrapy_by_webdriver()